package com.cupk.service.impl;

import com.cupk.common.PageResult;
import com.cupk.dto.AdminDto;
import com.cupk.dto.ProviderDto;
import com.cupk.dto.ProviderListDto;
import com.cupk.mapper.ProviderMapper;
import com.cupk.service.ProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 名称ProviderServiceImpl
 * 描述ProviderService实现类
 *
 * @version 1.0
 * @author:XiongRuiKai
 * @datatime:2023-06-12 10:38
 */
@Service
public class ProviderServiceImpl implements ProviderService {

    @Autowired
    private ProviderMapper providerMapper;

    /**
     * 供应商申请分页查询
     * @param id 供应商编号
     * @param name 供应商姓名
     * @param tele 供应商联系方式
     * @param page 页码
     * @param pageSize 每页返回的数据条目数
     * @return
     */
    @Override
    public PageResult<ProviderDto> getQueryResultsWithPaging(Integer id, String name, String tele, int page, int pageSize) {
        int start = (page - 1) * pageSize;
        List<ProviderDto> providerList = providerMapper.getProviderPage(id, name, tele, start, pageSize);
        long total = providerMapper.getProviderCount(id, name, tele);
        return new PageResult<>(providerList, total);
    }

    @Override
    public PageResult<ProviderListDto> getListQueryResultsWithPaging(Integer id, String providerName, String tele, int page, int pageSize) {
        int start = (page - 1) * pageSize;
        List<ProviderListDto> providerList2 = providerMapper.getProviderListPage(id, providerName, tele, start, pageSize);
        long total = providerMapper.getProviderListCount(id, providerName, tele );
        return new PageResult<>(providerList2, total);
    }


}
